import Vue from 'vue'
import Router from 'vue-router'
import {setStore,getSession} from '@/config/config';

Vue.use(Router)

let routerMain = new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component:()=>import(`@/page/login/login`)
    },
    {
      path: '/home',
      name: 'home',
      component:()=>import(`@/page/home/home`),
      redirect:'/homepage',
      children:[
        {
          path: '/homepage',
          name: 'homepage',
          component:()=>import(`@/page/homepage/homepage`)
        },
        {
          path: '/userManagement',
          name: 'userManagement',
          component: () => import(`@/page/userManagement/userManagement`),
          redirect: '/userManagement/userDataList',
          children: [
            {
              path: '/userManagement/userDataList',
              name: 'userDataList',
              component: () => import(`@/page/userManagement/userDataList`),
            },
            {
              path: '/userManagement/Money',
              name: 'Money',
              component: () => import(`@/page/userManagement/Money`),
            },
            {
              path: '/userManagement/userAddress',
              name: 'userAddress',
              component: () => import(`@/page/userManagement/userAddress`),
            }
          ]
        },
        {
          path: '/commodity',
          name: 'commodity',
          component: () => import(`@/page/commodity/commodity`),
          redirect: '/commodity/goodsList',
          children: [
            {
              path: '/commodity/goodsList',
              name: 'goodsList',
              component: () => import(`@/page/commodity/goodsList`),
            },
            {
              path: '/commodity/review',
              name: 'review',
              component: () => import(`@/page/commodity/review`),
            }, {
              path: '/commodity/classgoods',
              name: 'classgoods',
              component: () => import(`@/page/commodity/classgoods`),
            },{
              path: '/commodity/brand',
              name: 'brand',
              component: () => import(`@/page/commodity/brand`),
            },
            
          ]
        },
        {
          path: '/orders',
          name: 'orders',
          component: () => import(`@/page/orders/orders`),
          redirect: '/orders/orderManage',
          children: [
            {
              path: '/orders/orderManage',
              name: 'orderManage',
              component: () => import(`@/page/orders/orderManage`),
            },
            {
              path: '/orders/orderDetail',
              name: 'orderDetail',
              component: () => import(`@/page/orders/orderDetail`),
            },
            {
              path: '/orders/orderReason',
              name: 'orderReason',
              component: () => import(`@/page/orders/orderReason`),
            },
            {
              path: '/orders/orderApproval',
              name: 'orderApproval',
              component: () => import(`@/page/orders/orderApproval`),
            },
            {
              path: '/orders/delivery',
              name: 'delivery',
              component: () => import(`@/page/orders/delivery`),
            }
          ]
        },
        {
          path: '/promote',
          name: 'promote',
          component: () => import(`@/page/promote/promote`),
          redirect: '/promote/bulk',
          children: [
            {
              path: '/promote/bulk',
              name: 'bulk',
              component: () => import(`@/page/promote/bulk`),
            },
            {
              path: '/promote/advertising',
              name: 'advertising',
              component: () => import(`@/page/promote/advertising`),
            },
            {
              path: '/promote/ses',
              name: 'ses',
              component: () => import(`@/page/promote/ses`),
            },
            {
              path: '/promote/seckill',
              name: 'seckill',
              component: () => import(`@/page/promote/seckill`),
            },
            {
              path: '/promote/sesGoods',
              name: 'sesGoods',
              component: () => import(`@/page/promote/sesGoods`),
            },
            {
              path: '/promote/sesGoodShip',
              name: 'sesGoodShip',
              component: () => import(`@/page/promote/sesGoodShip`),
            },
          ]
        },
        {
          path: '/rightsManagement',
          name: 'rightsManagement',
          component: () => import(`@/page/rightsManagement/rightsManagement`),
          redirect: '/rightsManagement/administrator',
          children: [
            {
              path: '/rightsManagement/administrator',
              name: 'administrator',
              component: () => import(`@/page/rightsManagement/administrator`),
            },
            {
              path: '/rightsManagement/roleManagement',
              name: 'roleManagement',
              component: () => import(`@/page/rightsManagement/roleManagement`),
            }
          ]
        },
        {
          path: '/statistical',
          name: 'statistical',
          component: () => import(`@/page/statistical/statistical`),
          redirect: '/statistical/user',
          children: [
            {
              path: '/statistical/user',
              name: 'user',
              component: () => import(`@/page/statistical/user`),
            },
            {
              path: '/statistical/order',
              name: 'order',
              component: () => import(`@/page/statistical/order`),
            },
            {
              path: '/statistical/goods',
              name: 'goods',
              component: () => import(`@/page/statistical/goods`),
            }
          ]
        },
      ]
    }
  ]
});

routerMain.beforeEach((to,from,next)=>{
  if(getSession('token') || to.name=='login'){
    next()
  }else{
    next({path:'/'})
  }
  console.log(from.path,111,to.path);
  setStore('toRouter',to.path)
  setStore('fromRouter',from.path)
})

routerMain.afterEach((to,from)=>{
})
export default routerMain
